<?php
$arr = array();
foreach($chat as $chats):
$arr[] = $chats;
endforeach;
echo json_encode($arr);
?>